static DEFINE_SPINLOCK(console_lock);
+int xenlog_upper_thresh = XENLOG_UPPER_THRESHOLD;
+int xenlog_lower_thresh = XENLOG_LOWER_THRESHOLD;
+int xenlog_guest_upper_thresh = XENLOG_GUEST_UPPER_THRESHOLD;
+int xenlog_guest_lower_thresh = XENLOG_GUEST_LOWER_THRESHOLD;
+
+static int xen_startup = 1;
+
/*
* ********************************************************
* *************** ACCESS TO CONSOLE RING *****************
va_list args;
char *p, *q;
unsigned long flags;
+ int level = XENLOG_DEFAULT;
+ int upper_thresh = xenlog_upper_thresh;
+ int lower_thresh = xenlog_lower_thresh;
+ int print_regardless = xen_startup;
spin_lock_irqsave(&console_lock, flags);
va_end(args);
p = buf;
+
+ /* Is this print caused by a guest? */
+ if ( strncmp("<G>", p, 3) == 0 )
+ {
+ upper_thresh = xenlog_guest_upper_thresh;
+ lower_thresh = xenlog_guest_lower_thresh;
+ level = XENLOG_GUEST_DEFAULT;
+ p += 3;
+ }
+
+ if ( (p[0] == '<') &&
+ (p[1] >= '0') && (p[1] <= ('0' + XENLOG_MAX)) &&
+ (p[2] == '>') )
+ {
+ level = p[1] - '0';
+ p += 3;
+ }
+
+ if ( !print_regardless )
+ {
+ if ( level > upper_thresh )
+ goto out;
+ if ( (level >= lower_thresh) && (!printk_ratelimit()) )
+ goto out;
+ }
+
while ( (q = strchr(p, '\n')) != NULL )
{
*q = '\0';
start_of_line = 0;
}
+ out:
spin_unlock_irqrestore(&console_lock, flags);
}
/* Serial input is directed to DOM0 by default. */
switch_serial_input();
+
+ /* Now we implement the logging thresholds. */
+ xen_startup = 0;
}
void console_force_unlock(void)
#define EXPORT_SYMBOL(var)
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-/* Linux syslog levels. */
-#define KERN_NOTICE ""
-#define KERN_WARNING ""
-#define KERN_DEBUG ""
-#define KERN_INFO ""
-#define KERN_ERR ""
-#define KERN_CRIT ""
-#define KERN_EMERG ""
-#define KERN_ALERT ""
+/*
+ * The following log levels are as follows:
+ *
+ * XENLOG_ERR: Fatal errors, either Xen, Guest or Dom0
+ * is about to crash.
+ *
+ * XENLOG_WARNING: Something bad happened, but we can recover.
+ *
+ * XENLOG_INFO: Interesting stuff, but not too noisy.
+ *
+ * XENLOG_DEBUG: Use where ever you like. Lots of noise.
+ *
+ *
+ * Since we don't trust the guest operating system, we don't want
+ * it to allow for DoS by causing the HV to print out a lot of
+ * info, so where ever the guest has control of what is printed
+ * we use the XENLOG_GUEST to distinguish that the output is
+ * controled by the Guest.
+ *
+ * To make it easier on the typing, the above log levels all
+ * have a corresponding _G_ equivalent that appends the
+ * XENLOG_GUEST. (see the defines below).
+ *
+ */
+#define XENLOG_ERR "<0>"
+#define XENLOG_WARNING "<1>"
+#define XENLOG_INFO "<2>"
+#define XENLOG_DEBUG "<3>"
+
+#define XENLOG_GUEST "<G>"
+
+#define XENLOG_G_ERR XENLOG_GUEST XENLOG_ERR
+#define XENLOG_G_WARNING XENLOG_GUEST XENLOG_WARNING
+#define XENLOG_G_INFO XENLOG_GUEST XENLOG_INFO
+#define XENLOG_G_DEBUG XENLOG_GUEST XENLOG_DEBUG
+
+#define XENLOG_MAX 3
+
+/*
+ * To control the amount of printing, thresholds are added.
+ * These thresholds correspond to the above log levels.
+ * There's an upper and lower threshold for non-guests
+ * and Guest. This works as follows:
+ *
+ * If printk log level > upper threshold
+ * don't print anything
+ *
+ * If printk log level >= lower threshold
+ * rate limit the print (keep the amount down)
+ *
+ * Otherwise, just print.
+ *
+ * Note, in the above algorithm, to never rate limit
+ * simply make the lower threshold greater than the upper.
+ * This way the output will never be rate limited.
+ *
+ * For example:
+ * lower = 2; upper = 1;
+ * This will always print ERR and WARNING messages
+ * but will not print anything else. Nothing is
+ * rate limited.
+ */
+/*
+ * Defaults:
+ * For the HV, always print ERR and WARNING
+ * but nothing for INFO and DEBUG.
+ *
+ * For Guests, always rate limit ERR and WARNING
+ * but never print for INFO and DEBUG.
+ */
+#ifndef XENLOG_UPPER_THRESHOLD
+#define XENLOG_UPPER_THRESHOLD 1
+#endif
+#ifndef XENLOG_LOWER_THRESHOLD
+#define XENLOG_LOWER_THRESHOLD 2
+#endif
+#ifndef XENLOG_GUEST_UPPER_THRESHOLD
+#define XENLOG_GUEST_UPPER_THRESHOLD 1
+#endif
+#ifndef XENLOG_GUEST_LOWER_THRESHOLD
+#define XENLOG_GUEST_LOWER_THRESHOLD 0
+#endif
+
+/*
+ * The XENLOG_DEFAULT is the default given to printks that
+ * do not have any print level associated to it.
+ */
+#ifndef XENLOG_DEFAULT
+#define XENLOG_DEFAULT 1 /* Warning */
+#endif
+#ifndef XENLOG_GUEST_DEFAULT
+#define XENLOG_GUEST_DEFAULT 1 /* Warning */
+#endif
+
+/*
+ * Some code is copied directly from Linux.
+ * Match some of the Linux log levels to Xen.
+ * (Should these be Guest logs?? - SDR)
+ */
+#define KERN_ERR XENLOG_ERR
+#define KERN_CRIT XENLOG_ERR
+#define KERN_EMERG XENLOG_ERR
+#define KERN_WARNING XENLOG_WARNING
+#define KERN_NOTICE XENLOG_INFO
+#define KERN_INFO XENLOG_INFO
+#define KERN_DEBUG XENLOG_DEBUG
/* Linux 'checker' project. */
#define __iomem
#define __user
-#ifdef VERBOSE
#define DPRINTK(_f, _a...) printk("(file=%s, line=%d) " _f, \
__FILE__ , __LINE__ , ## _a )
-#else
-#define DPRINTK(_f, _a...) ((void)0)
-#endif
#ifndef __ASSEMBLY__
#include <xen/compiler.h>